﻿using System;
using System.Collections.Generic;

namespace Dqaqs.Web.Common
{
	public static class ObjectExtensions
	{
		public static TOut Safe<TIn, TOut>(this TIn obj, Func<TIn, TOut> memberAction)
		{
			//Note we should not use obj != null because it can not test value types and also
			//compiler has to lift the type to a nullable type for doing the comparision with null.
			return (EqualityComparer<TIn>.Default.Equals(obj, default(TIn))) ? default(TOut) : memberAction(obj);
		}
	}
}